//
//  PrepayTool.m
//  预购清单
//
//  Created by liujianlong on 2022/10/17.
//

#import "PrepayTool.h"

@implementation PrepayTool
+ (void)update:(Prepay *)pay complete:(nullable void(^) (BOOL success))block{
    [pay bg_saveOrUpdateAsync:^(BOOL isSuccess) {
        dispatch_async(dispatch_get_main_queue(), ^{
            if (block) {
                return block(isSuccess);
            }
        });
    }];
}
+ (void)find:(Budget*)model complete:(nullable void(^) (NSMutableArray <Prepay*>*result))block{
    NSString* where = [NSString stringWithFormat:@"where %@=%@ and %@=%@ and %@=%@",bg_sqlKey(@"account"),bg_sqlValue(model.account),bg_sqlKey(@"year"),bg_sqlValue(model.year),bg_sqlKey(@"month"),bg_sqlValue(model.month)];
    
    [Prepay bg_findAsync:nil where:where complete:^(NSArray * _Nullable array) {
        dispatch_async(dispatch_get_main_queue(), ^{
            if (block) {
                block([NSMutableArray arrayWithArray:array]);
            }
        });
    }];
}

+ (void)delete:(Prepay*)model complete:(nullable void(^) (BOOL success))block{
    NSString* where = [NSString stringWithFormat:@"where %@=%@ and %@=%@",bg_sqlKey(@"account"),bg_sqlValue(model.account),bg_sqlKey(@"stamp"),bg_sqlValue(@(model.stamp))];
    
    [Prepay bg_deleteAsync:nil where:where complete:^(BOOL isSuccess) {
        dispatch_async(dispatch_get_main_queue(), ^{
            if (block) {
                return block(isSuccess);
            }
        });
    }];
}
@end
